/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-10-16
 * Time: 19:29
 */
public class test_1 {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * @param string string字符串
     * @return int整型
     */
    public int getLongestPalindrome(String string) {
        char[] chars = string.toCharArray();
        int right = 0;
        int left = 0;
        int ret = 0;
        for (int i = 1; i < chars.length - 1; i++) {
            //分类回文为单数和回文为偶数

            //1.为单数回文的中心
            left = i - 1;
            right = i + 1;
            while (left >= 0 && right < chars.length && chars[left] == chars[right]) {
                left--;
                right++;
            }
            ret = Math.max(ret, right - left - 1);
            //2.为偶数回文中心
            left = i;
            right = i + 1;
            while (left >= 0 && right < chars.length && chars[left] == chars[right]) {
                left--;
                right++;
            }
            ret = Math.max(ret, right - left - 1);
            System.out.println(ret);
        }

        return ret;
    }
}
